//app.js
App({
  onLaunch: function (options) {
    //调用API从本地缓存中获取数据
    // var logs = wx.getStorageSync('logs') || []
    // logs.unshift(Date.now())
    wx.setStorageSync("scope", false)
    wx.setStorageSync("scene", options.scene)
    // console.log("转发数据" +options.shareTicket)
   var  that = this;
   
    wx.login({
      success: function (res) {

          wx.checkSession({
            success: function(e){
              console.log("登入状态")

              if (wx.getStorageSync("token") == "" || wx.getStorageSync("token") == null) {
                   that.login(res)

              }
            },fail: function(e){
              console.log("登入会话失效")
              that.login(res);
            }
          })



      }
    })
  },
  onShow: function (options){


   
  },

  login:function(res){
    wx.request({
      url: getApp().globalData.url + '/app/login',
      data: {
        code: res.code
      },
      success: function (res) {
        wx.setStorageSync("token", res.data.data)

        if (res.data.code != 200) {
          // 登录错误
          wx.hideLoading();
          // wx.showModal({
          //   title: '提示',
          //   content: '无法登录，请重试',
          //   showCancel:false
          // })
          return;
        }


      }
    })
  },

  globalData: {
    userInfo: null,
    awardsConfig: {},
    url:"https://ty108.com/dazhuanpan-four",
    // url:"http://localhost:8080",
    // url:"http://5n8e8y.natappfree.cc",
    runDegs: 0
  }



  
  // getUserInfo:function(cb){
  //   var that = this
  //   if(this.globalData.userInfo){
  //     typeof cb == "function" && cb(this.globalData.userInfo)
  //   }else{
  //     //调用登录接口
  //     wx.login({
  //       success: function () {
  //         wx.getUserInfo({
  //           success: function (res) {
  //             that.globalData.userInfo = res.userInfo
  //             typeof cb == "function" && cb(that.globalData.userInfo)
  //           }
  //         })
  //       }
  //     })
  //   }
  // },
 
})